package com.thread.demo1;

import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ThreadPool {
	
	private static void test0(){
//		ExecutorService executor = Executors.newFixedThreadPool(2);
//		ExecutorService executor = new ThreadPoolExecutor(10,10,60L,TimeUnit.SECONDS,new ArrayBlockingQueue(10));
		
		ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
		        .setNameFormat("demo-pool-%d").build();
		ExecutorService executor = new ThreadPoolExecutor(5, 200,
		        0L, TimeUnit.MILLISECONDS,
		        new LinkedBlockingQueue<Runnable>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
		for (int i = 0; i < 10; i++) {
			int index = i;
            executor.execute(()->{
            	try {
            		log.info(index+"=="+new Date()+";线程名字："+Thread.currentThread().getName());
                    Thread.sleep(1000);
//                    System.out.println("##"+new Date());
                } catch (Exception e) {
                }

            });
        }
	}
	
	public static void main(String[] args) {
		test0(); 
	}
}
